home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / KBANDATA / LINEELEM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-23  |  2.9 KB  |  111 lines

  1. // the declaration of class LINE_ELEMENT
  2. // Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  3.  
  4. #ifndef _LINEELEM_H_
  5. #define _LINEELEM_H_
  6.  
  7. #include "../common/typedef.h"
  8. #include "../finfo.h"
  9. #include "../xy.h"
  10.  
  11. class LINE_ELEMENT {
  12.   bool  m_select;
  13.   XY    m_ac_s;
  14.   XY    m_ac_e;
  15.   uint  m_width;
  16. public:
  17.   // constructors
  18.  
  19.   LINE_ELEMENT()
  20.     : m_select(false),
  21.       m_ac_s  (     ),
  22.       m_ac_e  (     ),
  23.       m_width (0    ) {}
  24.   LINE_ELEMENT(const LINE_ELEMENT& src)
  25.     : m_select(src.m_select),
  26.       m_ac_s  (src.m_ac_s  ),
  27.       m_ac_e  (src.m_ac_e  ),
  28.       m_width (src.m_width ) {}
  29.   LINE_ELEMENT(const XY& ac_s, const XY& ac_e, uint width)
  30.     : m_select(false),
  31.       m_ac_s  (ac_s ),
  32.       m_ac_e  (ac_e ),
  33.       m_width (width) {}
  34.  
  35.   // operators
  36.  
  37.   bool operator==(const LINE_ELEMENT& r) const {
  38.     return (ac_s()  == r.ac_s())
  39.         && (ac_e()  == r.ac_e())
  40.         && (width() == r.width());
  41.   }
  42.   bool operator!=(const LINE_ELEMENT& r) const {
  43.     return !(*this == r);
  44.   }
  45.   bool operator<(const LINE_ELEMENT& r) const { return true; }
  46.   bool operator>(const LINE_ELEMENT& r) const { return true; }
  47.  
  48.   // accessors
  49.  
  50.   bool is_selected() const { return m_select; }
  51.   const XY& ac_s() const { return m_ac_s;  }
  52.   const XY& ac_e() const { return m_ac_e;  }
  53.   uint  width()    const { return m_width; }
  54.  
  55.   void  select  () { m_select = true;  }
  56.   void  unselect() { m_select = false; }
  57.   void  set_ac_s(const XY& ac) { m_ac_s   = ac;    }
  58.   void  set_ac_e(const XY& ac) { m_ac_e   = ac;    }
  59.   void  set_width(uint width)  { m_width  = width; }
  60.  
  61.   // max and min
  62.  
  63.   XY    get_max() const {
  64.     return ::get_max(ac_s(), ac_e()) + width() / 2;
  65.   }
  66.   XY    get_min() const {
  67.     return ::get_min(ac_s(), ac_e()) - width() / 2;
  68.   }
  69.  
  70.   // block-related
  71.  
  72.   LINE_ELEMENT shift(const XY& ac_base) const {
  73.     LINE_ELEMENT ans = *this;
  74.     ans.set_ac_s(ac_s() + ac_base);
  75.     ans.set_ac_e(ac_e() + ac_base);
  76.     return ans;
  77.   }
  78.  
  79.   int   is_in_block(const XY& ac1, const XY& ac2) const {
  80.     return ac_s().is_in_box(ac1, ac2) || ac_e().is_in_box(ac1, ac2);
  81.   }
  82.  
  83.   // save and load
  84.  
  85.   void  save_200a8(FILE_NEW& fp) const;
  86. private:
  87.   int   unit_change_micron2kban(int micron);
  88.   int   load_170_core(const char *str);
  89. public:
  90.   int   load_primitive_170(const char *str);
  91.   int   load_component_170(const char *str);
  92.   void  load_200a8(const char* str);
  93.  
  94.   // miscellaneous
  95.  
  96.   int   is_holizontal() const { return ac_s().y() == ac_e().y(); }
  97.   int   is_vertical()   const { return ac_s().x() == ac_e().x(); }
  98.   int   is_slash() const {
  99.     return (ac_s().x() - ac_e().x()) == (ac_s().y() - ac_e().y());
  100.   }
  101.   int   is_backslash() const {
  102.     return (ac_s().x() - ac_e().x()) == (ac_e().y() - ac_s().y());
  103.   }
  104.   int   is_on_line(XYT eps, const XY& ac);
  105.  
  106.   void  rotate_90();
  107.   uint  GetMinimumRadius() const { return width() / 2; }
  108. };
  109.  
  110. #endif /* _LINEELEM_H_ */
  111.